var router = require('libs/router').router;
var pages = require('libs/pages');
var ItemMixin = require('mixins/item');
var libs = require('libs/libs');
var api = libs.api;
var valide = libs.formValide;


//当前页公共变量
var _page = {}


var bindEvent = function(){
    //此处各种dom 操作

};

//演示模块
var MessageDetails = React.createClass({
    mixins: [ItemMixin],
    render:function(){
        var _data = this.props.data;
        if (_data.code===0){
            return <div className="uc-message-empty" id="uc-message-empty" style={{display:'block'}}>
                <div>该消息不存在</div>
            </div>
        }
        return (
            <div className="uc-message">
                <div className="uc-message-details">
                    <div className="uc-message-img"><img src={_data.imgUrl} /></div>
                    <h1 className="uc-message-title">{_data.title}</h1>
                    <p className="uc-message-time">{_data.createTime}</p>
                    <div className="uc-message-article">
                        {_data.content}
                    </div>
                </div>
            </div>
        );
    }
});

function start(name){
    return pages.new({
        boot:function(){},
        trigger:function(){
            this.libs.changeTitle('消息中心');    //更改当前页面标题
            var messageId = sessionStorage.getItem('messageId');
            var login = SA.get('USER').login;
            var params = {
                method:'get',
                login:login,
                messageId:messageId
            };
            var _this = this;
            api.req('/messageDetail',params,function(data){
                _this.main(_this,data);
            });
        },
        ready: function(){
        },
        main: function(self,data){
            this.render(
                <MessageDetails itemDefaultMethod={bindEvent} data={data} />,
                document.getElementById(name)
            )
        },
        end: function(){
            React.unmountComponentAtNode(document.getElementById(name))
        }
    })
}

module.exports = start;
